import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

//自定义 一个 路由类, 继承自 FluroRouter, 重新 navitionTo方法, 可以在跳转时做路由拦截

class PermissionRouter extends FluroRouter{
  late List<String> _whiteList;
  set whiteList(value) => _whiteList = value;

  late String _permissionDefinePath;
  set permissionDefinePath(value) => _permissionDefinePath = value;

  Future navitionTo(
    BuildContext context,
    String path, {
      bool replace = false,
      bool clearStack = false,
      bool maintainState = true,
      bool rootNavigator = false,
      TransitionType transitionType = TransitionType.inFromRight,
      transitionBuilder,
      required RouteSettings routeSettings,
      }){
        //做一个路由拦截
        String pathToNavigate = path;
        AppRouteMatch? routeMatch = this.match(path);
        String routePathMatched = routeMatch!.route.route;
        if (!_whiteList.contains(routePathMatched)) {
          pathToNavigate = _permissionDefinePath;
        }
        return super.navigateTo(
          context, 
          pathToNavigate,
          replace: replace,
          clearStack: clearStack,
          maintainState: maintainState,
          rootNavigator: rootNavigator,
          routeSettings: routeSettings,
          transitionBuilder: transitionBuilder,
          transition: transitionType,
        );
      }

  










}
